'use strict';

var mongoose = require('mongoose'),
    Schema = mongoose.Schema,
    baseController = require('../../../Base/server/controllers/BaseDoc.js');

var roleModel = baseController.getBaseDocFields();
roleModel.Code = {
    type: String,
    default: '',
    trim: true
};

roleModel.Name = {
    type: String,
    default:'',
    trim: true
};

roleModel.Menus = {
    type: [
        {
            type: Schema.ObjectId,
            ref: 'Menu'
        }
    ]
};

roleModel.IsEffective = {
    type: Boolean
};

var roleSchema = new Schema(roleModel);
roleSchema.index({Name: 1});
roleSchema.index({Code: 1}, {"unique": true});

mongoose.model('Role', roleSchema, 'Role');
